package com.ok.cartoon.service.impl;

import com.ok.cartoon.domain.po.OkCartoon;
import com.ok.cartoon.domain.po.OkCollection;
import com.ok.cartoon.mapper.OkCollectionMapper;
import com.ok.cartoon.service.IOkCartoonService;
import com.ok.cartoon.service.IOkCollectionService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ok.common.utils.UserContext;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 * 收藏表 服务实现类
 * </p>
 *
 * @author lhw
 * @since 2024-05-13
 */
@Service
@RequiredArgsConstructor
public class OkCollectionServiceImpl extends ServiceImpl<OkCollectionMapper, OkCollection> implements IOkCollectionService {

    private final IOkCartoonService okCartoonService;

    @Override
    @Transactional
    public void add(Long cartoonId) {
        OkCollection okCollection = new OkCollection();
        okCollection.setCartoonId(cartoonId);
        okCollection.setUserId(UserContext.getUser());
        //添加收藏数据
        this.save(okCollection);
        //修改漫画信息
        OkCartoon cartoon = okCartoonService.getById(cartoonId);
        cartoon.setCollectNum(cartoon.getCollectNum()+1);
        okCartoonService.updateById(cartoon);

    }
}
